#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;

/*
所谓的边界条件，肯定是很特殊情况下存在的，比如算法运行到了一个很小规模。
或者很特殊输入的情况下。
 */
class Solution {
public:
    int findMin(vector<int>& nums) {
      int left = 0;
      int right = nums.size() - 1;
      int temp = -1;
      while(left <= right){
	int mid = left + ((right - left) >> 1);
	if(nums[mid] > max(nums[left],nums[right])){
	  left = mid + 1;
	}else if(nums[mid] < min(nums[left],nums[right])){
	  right = mid - 1;
	}else if(nums[mid] < nums[left]){
	  left = mid + 1;
	}else if(nums[mid] < nums[right]){
	  right = mid - 1;
	}else{
	  left = mid + 1;
	}
	if(temp == -1 || nums[temp] > nums[mid]){
	  temp = mid;
	}
      }
      return nums[temp];
    }
};

int main() {
  Solution s;
  vector<int> a = {2,1};
  cout<<s.findMin(a)<<endl;
}
